//
//  DbTable.m
//  MarketDataColloctor
//
//  Created by jiro on 10/03/10.
//  Copyright 2010 jiro music. All rights reserved.
//

#import "DbTableEntry_.h"
#import "../../Commons.h"
#import "libpq-fe.h"
#import "../Nodes.h"

@implementation DbTableEntry_

+ (NSString*) querySelectAllWithClauses: (NSArray*) clauses
{
	@throw ( [ NSException exceptionWithName: kText_NeedInheritClassImplementation reason: @""  userInfo: nil ] ); 
}

+ (NSString*) tableName
{
	@throw ( [ NSException exceptionWithName: kText_NeedInheritClassImplementation reason: @""  userInfo: nil ] ); 
}

+ (NSString*) querySelectAllWithTableName: (NSString*) tableName andClauses: (NSArray*) clauses
{
/*
	NSMutableString* c = [ NSMutableString string ];
	NSEnumerator* e = [ clauses objectEnumerator ];
	ClauseNode* clause;
	while ( clause = [ e nextObject ] )
	{
		[ c appendFormat: @" %@ ", clause->query() ];
	}
	NSString* s = [ NSString stringWithFormat: @"select * from %@ %@;", tableName, c ];
	return s;
	*/
	return nil;
}

+ (NSString*) querySelectFields: (NSArray*) fieldNoeds tableName: (NSString*) tableName andClauses: (NSArray*) clauses
{/*
	NSMutableString* c = [ NSMutableString string ];
	NSEnumerator* e = [ clauses objectEnumerator ];
	ClauseNode* clause;
	while ( clause = [ e nextObject ] )
	{
		[ c appendFormat: @" %@ ", clause->query() ];
	}
	
	NSMutableString* fields = [ NSMutableString string ];
	e = [ fieldNoeds objectEnumerator ];
	for ( int i = 0, count = [ fieldNoeds count ]; i < count; i++ )
	{
		[ fields appendString: [ [ fieldNoeds objectAtIndex: i ] query ] ];
		if ( i != count - 1 )
		{
			[ fields appendString: @", " ];
		}
	}
	NSString* s = [ NSString stringWithFormat: @"select %@ from %@ %@;", fields, tableName, c ];
	return s;*/
	
	return nil;
}


+ (int) dataCountWithTableName: (NSString*) tableName andWhereClause: (WhereNode*) conditionNode
{
/*
	NSString* condition = @"";
	if ( conditionNode != nil )
	{
		condition = [ conditionNode query ];
	}
 	DbOperator* ope = [ DbOperator defaultOperator ];
	NSString* s = [ NSString stringWithFormat: @"select count( * ) from %@ %@;", tableName, condition ];
//	NSLog( @"%@", s );
	PGresult* result = nil;
	int count;
	[ ope executeQuery: s intoResult: & result ];
	if ( result == nil )
	{
		return 0;
	}
	count = atoi( PQgetvalue( result, 0, 0 ) );
	PQclear( result );

	return count;
*/
	return 0;
}

- (NSString*) sqlInsertStatement
{
	NSException* exception =
	 [ [ NSException alloc ] 
		initWithName: kText_NotImplementedException 
		reason: kText_SelectorIsNotImplemented 
		userInfo: nil ];
	@throw exception;

	return nil;
}

- (NSString*) tableName
{
	NSException* exception =
	 [ [ NSException alloc ] 
		initWithName: kText_NotImplementedException 
		reason: kText_SelectorIsNotImplemented 
		userInfo: nil ];
	@throw exception;
	
	return nil;
}

- (NSString*) queryCreateTable
{
	NSException* exception =
	 [ [ NSException alloc ] 
		initWithName: kText_NotImplementedException 
		reason: kText_SelectorIsNotImplemented 
		userInfo: nil ];
	@throw exception;
}

+ (NSString*) queryFieldsOfCreateTable
{
	NSException* exception =
	 [ [ NSException alloc ] 
		initWithName: kText_NotImplementedException 
		reason: kText_SelectorIsNotImplemented 
		userInfo: nil ];
	@throw exception;
}

+ (NSString*) queryCreateTable
{
	NSException* exception =
	 [ [ NSException alloc ] 
		initWithName: kText_NotImplementedException 
		reason: kText_SelectorIsNotImplemented 
		userInfo: nil ];
	@throw exception;

	return nil;
}

+ (NSString*) queryInsertInitialValues
{
	return @"";
}

+ (NSString*) querySelectAll
{
	@throw ( [ NSException exceptionWithName: kText_NeedInheritClassImplementation reason: @""  userInfo: nil ] );
}

+ (NSString*) querySelectAllOrderBy: (NSString*) columns
{
	@throw ( [ NSException exceptionWithName: kText_NeedInheritClassImplementation reason: @""  userInfo: nil ] );
}

+ (NSString*) querySelectWithWhereClause: (ExpressionNode*) condition andOrdeyByClaus: (OrderByNode*) orderBy
{
	@throw ( [ NSException exceptionWithName: kText_NeedInheritClassImplementation reason: @""  userInfo: nil ] );
}

- (NSString*) queryInsert
{
	@throw ( [ NSException exceptionWithName: kText_NeedInheritClassImplementation reason: @""  userInfo: nil ] ); }

- (NSString*) queryInsertValue
{
	@throw ( [ NSException exceptionWithName: kText_NeedInheritClassImplementation reason: @""  userInfo: nil ] ); 
}

+ (NSString*) querySelectFields: (NSArray*) fieldNodes andClauses: (NSArray*) clauses
{
	@throw ( [ NSException exceptionWithName: kText_NeedInheritClassImplementation reason: @""  userInfo: nil ] );
}

@end
